package com.altersoftware.hotel.dao;

import org.apache.ibatis.annotations.*;

import com.altersoftware.hotel.entity.StaffDO;

import javax.annotation.Resource;

/**
 * @author czy@win10
 * @date 2020/1/21 21:49
 */
@Mapper
public interface StaffDAO {
    /**
     * 插入一个用户
     * t
     * 
     * @param staffDO
     */
    @Insert(" INSERT INTO tb_staff (staff_number, staff_name, department_number, grouppermission_number, staff_sex, staff_age, staff_tel, staff_account, staff_password, staff_faceid, staff_mail, create_time, modify_time ) "
        +
        "VALUES(#{id}, #{name}, #{departmentID}, #{permissionGroupId}, #{sex}, #{age}, #{contactPhone}, #{account}, #{password}, #{faceID}, #{mail}, NOW(), NOW()) ")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "staff_number")
    void insert(StaffDO staffDO);

    /**
     * id查询用户
     *
     * @param id
     * @return
     */

    @Select(" select staff_number, staff_name, department_number, grouppermission_number, staff_sex, staff_age, staff_tel, staff_account, staff_password, staff_faceid, staff_mail, create_time, modify_time"
        +
        " from tb_staff where staff_number=#{id} ")
    @Results({
        @Result(property = "id", column = "staff_number"),
        @Result(property = "name", column = "staff_name"),
        @Result(property = "departmentID", column = "department_number"),
        @Result(property = "permissionGroupId", column = "grouppermission_number"),
        @Result(property = "sex", column = "staff_sex"),
        @Result(property = "age", column = "staff_age"),
        @Result(property = "contactPhone", column = "staff_tel"),
        @Result(property = "account", column = "staff_account"),
        @Result(property = "password", column = "staff_password"),
        @Result(property = "faceID", column = "staff_faceid"),
        @Result(property = "mail", column = "staff_mail"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    StaffDO getStaffDOById(@Param("id") long id);

    /**
     * 用户账号和密码验证用户
     *
     * @param password
     * @param contactPhone
     * @return
     */

    @Select("select staff_number, staff_name, department_number, grouppermission_number, staff_sex, staff_age, staff_account, staff_faceid, staff_mail, create_time, modify_time"
        +
        " from tb_staff where staff_tel=#{contactPhone} and staff_password=#{password}")
    @Results({
        @Result(property = "id", column = "staff_number"),
        @Result(property = "name", column = "staff_name"),
        @Result(property = "departmentID", column = "department_number"),
        @Result(property = "permissionGroupId", column = "grouppermission_number"),
        @Result(property = "sex", column = "staff_sex"),
        @Result(property = "age", column = "staff_age"),
        @Result(property = "account", column = "staff_account"),
        @Result(property = "faceID", column = "staff_faceid"),
        @Result(property = "mail", column = "staff_mail"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    StaffDO getUserDOByMobileAndPassword(@Param("contactPhone") String contactPhone,
        @Param("password") String password);

    /**
     * 更新员工信息
     *
     * @param staffDO
     * @return
     */
    @Update("update tb_staff  set staff_name=#{name}, department_number=#{departmentID}, grouppermission_number=#{permissionGroupId},  staff_sex=#{sex}, staff_age=#{age}, staff_tel=#{contactPhone}, staff_account=#{account}, staff_password=#{password}, staff_faceid=#{faceID}, staff_mail=#{mail}, modify_time=now()"
        +
        "where staff_number=#{id}")
    int update(StaffDO staffDO);

    /**
     * id删除用户
     *
     * @param id
     */
    @Delete("DELETE FROM tb_staff WHERE staff_number=#{id}")
    void deleteById(long id);

    /**
     * 手机账号查询用户
     *
     * @param contactPhone
     * @return
     */
    @Select("select staff_number, staff_name, department_number, grouppermission_number, staff_sex, staff_age, staff_tel, staff_account, staff_faceid, staff_mail, create_time, modify_time"
        +
        " from tb_staff where staff_tel=#{contactPhone}")
    @Results({
        @Result(property = "id", column = "staff_number"),
        @Result(property = "name", column = "staff_name"),
        @Result(property = "departmentID", column = "department_number"),
        @Result(property = "permissionGroupId", column = "grouppermission_number"),
        @Result(property = "sex", column = "staff_sex"),
        @Result(property = "age", column = "staff_age"),
        @Result(property = "account", column = "staff_account"),
        @Result(property = "faceID", column = "staff_faceid"),
        @Result(property = "mail", column = "staff_mail"),
        @Result(property = "contactPhone", column = "staff_tel"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    StaffDO getStaffDOByPhobe(@Param("contactPhone") String contactPhone);

    /**
     * 邮箱查找用户
     *
     * @param mail
     * @return
     */
    @Select(" select staff_number, staff_name, department_number, grouppermission_number, staff_sex, staff_age, staff_tel, staff_account, staff_password, staff_faceid, staff_mail, create_time, modify_time"
        +
        " from tb_staff where staff_mail=#{mail} ")
    @Results({
        @Result(property = "id", column = "staff_number"),
        @Result(property = "name", column = "staff_name"),
        @Result(property = "departmentID", column = "department_number"),
        @Result(property = "permissionGroupId", column = "grouppermission_number"),
        @Result(property = "sex", column = "staff_sex"),
        @Result(property = "age", column = "staff_age"),
        @Result(property = "contactPhone", column = "staff_tel"),
        @Result(property = "account", column = "staff_account"),
        @Result(property = "password", column = "staff_password"),
        @Result(property = "faceID", column = "staff_faceid"),
        @Result(property = "mail", column = "staff_mail"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    StaffDO getStaffDOByMail(@Param("mail") String mail);

    /**
     * faceToken查找员工
     *
     * @param faceId
     * @return
     */
    @Select("select staff_number, staff_name, department_number, grouppermission_number, staff_sex, staff_age, staff_account, staff_faceid, staff_mail, create_time, modify_time"
        +
        " from tb_staff where staff_faceid=#{faceId}")
    @Results({
        @Result(property = "id", column = "staff_number"),
        @Result(property = "name", column = "staff_name"),
        @Result(property = "departmentID", column = "department_number"),
        @Result(property = "permissionGroupId", column = "grouppermission_number"),
        @Result(property = "sex", column = "staff_sex"),
        @Result(property = "age", column = "staff_age"),
        @Result(property = "contactPhone", column = "staff_tel"),
        @Result(property = "account", column = "staff_account"),
        @Result(property = "password", column = "staff_password"),
        @Result(property = "mail", column = "staff_mail"),
        @Result(property = "createTime", column = "create_time"),
        @Result(property = "modifyTime", column = "modify_time")
    })
    StaffDO getStaffDOByFaceToken(@Param("faceId") String faceId);

    /**
     * 部门查找员工
     */
}
